package com.gxa.controller;

import com.gxa.common.Result;
import com.gxa.pojo.Emp;
import com.gxa.service.EmpService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 针对雇员信息实现基本的crud功能
 */
@Controller
@Api(value = "雇员数据test",tags = "雇员数据接口API")
@RequestMapping("/emp")
public class EmpController {

    @Autowired
    private EmpService empService;

    @RequestMapping(value = "/addEmp",method = RequestMethod.POST)
    @ApiOperation(value = "添加雇员接口",notes = "提交雇员信息",httpMethod = "post", response = Result.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
//    @ApiIgnore  //定义在类上，代表此类会swagger忽略，定义在方法上，代表此方法被swagger忽略
    @ResponseBody
    public Result addEmp(@RequestBody @ApiParam(name = "Emp",value = "雇员信息",required = false)  Emp emp){
        Result result = empService.addEmp(emp);
        return result;
    }

    @RequestMapping(value = "/deleteEmp",method = RequestMethod.POST)
    @ApiOperation(value = "删除雇员接口",notes = "提交所删除雇员编号",httpMethod = "post", response = Result.class)
    @ApiImplicitParam(name = "empno",value = "雇员编号",required = true,dataType = "String",paramType = "query",readOnly = true)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
//    @ApiIgnore  //定义在类上，代表此类会swagger忽略，定义在方法上，代表此方法被swagger忽略
    @ResponseBody
    public Result deleteEmp(@RequestParam(name = "empno") Integer empno){
        Result result = empService.deleteEmp(empno);
        return result;
    }
    @RequestMapping(value = "/updateEmp",method = RequestMethod.POST)
    @ApiOperation(value = "更新雇员接口",notes = "提交所更新雇员信息",httpMethod = "post", response = Result.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public Result updateEmp(@RequestBody Emp emp){
        Result result = empService.updateEmp(emp);
        return result;
    }
    @RequestMapping(value = "/selectEmp",method = RequestMethod.GET)
    @ApiOperation(value = "查询雇员接口",notes = "提交所查询雇员编号",httpMethod = "get", response = Result.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public Result selectEmp(Integer empno){
        Result result = empService.selectEmp(empno);
        return result;
    }
}
